package com.wuyangnju.healthclub.service;

import java.util.List;

import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.wuyangnju.healthclub.dao.FamilyDao;
import com.wuyangnju.healthclub.entity.Family;

@Component
public class FamilyService {

	@PersistenceContext
	protected EntityManager em;

	@Resource
	private FamilyDao familyDao;

	@Transactional
	public String post(Family family) {
		familyDao.create(em, family);
		return family.getCardId();
	}

	@Transactional
	public Family get(String cardId) {
		return familyDao.retrieve(em, Long.valueOf(cardId));
	}

	@Transactional
	public List<Family> get() {
		return familyDao.retrieve(em);
	}

	@Transactional
	public void put(Family family) {
		familyDao.update(em, family.getId(), family);
	}

	@Transactional
	public void delete(Family family) {
		familyDao.delete(em, family.getId());
	}

}
